<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var leaguerDataGrid;
    var leaguerDepartmentTree;
	var associationGrid;
    $(function() {
        leaguerDepartmentTree = $('#leaguerDepartmentTree').tree({
        	lines:true,
            url : '${path }/admin/association/tree',
            parentField : 'pid',
            lines : true,
            animate: true,
            onClick : function(node) {
            	$(this).tree('toggle', node.target);
                 var grid = jQuery('#associationGrid');
                 var queryParams = grid.datagrid('options').queryParams; 
                 queryParams.page=1; 
                 queryParams.rows=99999999;
                 queryParams.departmentid=node.id;
				 grid.datagrid('options').queryParams=queryParams;	
			     grid.datagrid('options').url="${path }/admin/association/dataGrid";
			     grid.datagrid('reload');
            }
        });
		 associationGrid = $('#associationGrid').datagrid({
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : false,
            singleSelect : true,
            idField : 'id',
            sortName : 'sequence',
	        sortOrder : 'asc',
			onClickRow:function(rowIndex,rowData){
			   $('#associationId').val(rowData.id);
                 var grid = jQuery('#leaguerDataGrid');
                 var queryParams = grid.datagrid('options').queryParams; 
                 queryParams.page=1; 
                 queryParams.rows=99999999;
                 queryParams.associationId=rowData.id;
				 grid.datagrid('options').queryParams=queryParams;	
			     grid.datagrid('options').url="${path }/admin/leaguer/dataGrid";
			     grid.datagrid('reload');
			  },
            pageSize : 10,
            pageList : [ 10, 20],
            columns : [ [ {
                width : '110',
                title : '社团名称',
                field : 'association_name',
                sortable : true
            }] ]
        });
	
        leaguerDataGrid = $('#leaguerDataGrid').datagrid({
           // url : '${path }/admin/leaguer/dataGrid',
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'sequence',
	        sortOrder : 'asc',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            columns : [ [ {
                width : '150',
                title : '会员名称',
                field : 'true_name',
                sortable : true
            },{
                width : '50',
                title : '性别',
                field : 'sex',
                formatter : function(value, row, index) {
                    switch (value) {
                    case '0':
                        return '女';
                    case '1':
                        return '男';
                    }
                }
            },{
                width : '80',
                title : '加入日期',
                field : 'join_date',
                sortable : true
            },{
                width : '50',
                title : '缴费',
                field : 'dues'
            },{
                width : '150',
                title : '邮箱',
                field : 'email',
                sortable : true
            },{
                width : '120',
                title : '联系电话',
                field : 'telephone',
                sortable : true
            },{
                width : '120',
                title : '班级',
                field : 'class_name',
                sortable : true
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '停用';
                    case 1:
                        return '正常';
                    }
                }
            } , {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/admin/leaguer/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="leaguer-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editLeaguerFun(\'{0}\');" >查看</a>', row.id);
                        </shiro:hasPermission>
                        /* <shiro:hasPermission name="/admin/leaguer/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="leaguer-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteLeaguerFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission> */
                    return str;
                }
            } 
            ] ],
            onLoadSuccess:function(data){
                $('.leaguer-easyui-linkbutton-edit').linkbutton({text:'查看'});
                $('.leaguer-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#leaguerToolbar'
        });
    });
      //获取父id
    function getAssociationId(){
    	var associationId=$("#associationId").val();
    	return associationId;
    }  
     function addLeaguerFun() {
     	var associationId=$("#associationId").val();
	    if (associationId==null||associationId==""||associationId==undefined) {
			parent.$.messager.alert('提示', "请选择左侧的所属社团信息", 'info');
			return false;
		}
        parent.$.modalDialog({
            title : '添加',
            width : 600,
            height : 400,
            href : '${path }/admin/leaguer/add',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = leaguerDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#leaguerEditForm');
                    f.submit();
                }
            } ]
        });
    }
     function editLeaguerFun(id) {
        if (id == undefined) {
            var rows = leaguerDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            leaguerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 600,
            height : 400,
            href : '${path }/admin/leaguer/edit?id='+id
            /* ,buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = leaguerDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#leaguerEditForm');
                    f.submit();
                }
            } ] */
        });
    }
    
    function deleteLeaguerFun(id) {
     if (id == undefined) {
        	var rows = leaguerDataGrid.datagrid('getSelections');
        	id = rows[0].id;
        } else {
            leaguerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/admin/leaguer/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        leaguerDataGrid.datagrid('reload');
                        $("#leaguerDepartmentTree").tree("reload");
                    } else {
                        parent.$.messager.alert('错误', result.msg, 'error');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
    
    function searchLeaguerFun() {
    	$("#leaguerDepartmentTree").tree("reload");
        leaguerDataGrid.datagrid('load', $.serializeObject($('#searchLeaguerForm')));
    }
    function cleanLeaguerFun() {
        $('#searchLeaguerForm input').val('');
        leaguerDataGrid.datagrid('load', {});
    }
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'east',split:true" title="会员信息列表" style="width:75%;">
			 <table id="leaguerDataGrid" data-options="fit:true,border:false"></table>
		</div>
		<div data-options="region:'west',split:true" title="院系栏目" style="width:160px;">
			<ul id="leaguerDepartmentTree" fit="true" style="width:140px;margin: 10px 10px 10px 10px"></ul>
		</div>
		<div clsss="association" data-options="region:'center',title:'社团列表',iconCls:'icon-ok'" style="width:25%;">
			 <table id="associationGrid" data-options="fit:true,border:false"></table>
		</div>
	</div>
<div id="leaguerToolbar" style="display: none;">
        <form id="searchLeaguerForm">
       		<input name="associationId" type="hidden" id="associationId" value=""/>
            <table>
                <tr>
                    <th>会员名称:</th>
                    <td><input name="trueName" placeholder="请输入会员名称"/>
                     	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchLeaguerFun();">查询</a>
                     	<%-- <shiro:hasPermission name="/admin/leaguer/add">
					        <a onclick="addLeaguerFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus '">添加</a>
					    </shiro:hasPermission> --%> 	
                	</td>
                </tr>
            </table>
        </form>
</div>